package com.synergy.stockflow.sales.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.synergy.stockflow.model.Result;
import com.synergy.stockflow.sales.entity.QuoteDetails;
import com.synergy.stockflow.sales.entity.ShipmentHistory;
import com.synergy.stockflow.sales.entity.ShippingDetails;
import com.synergy.stockflow.sales.service.QuoteDetailsService;
import com.synergy.stockflow.sales.service.ShippingDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/shippingDetails")
public class ShippingDetailsController {

    @Autowired
    ShippingDetailsService shippingDetailsService;

    @PostMapping("/select")
    public Result<List<ShippingDetails>> selectShippingDetails(@RequestBody List<ShippingDetails> shippingDetails){
        List<ShippingDetails> shippingDetails1 = new ArrayList<>();
        for(ShippingDetails shippingDetail : shippingDetails){
            System.out.println(shippingDetail);
            shippingDetails1.add(shippingDetailsService.select(shippingDetail.getShippingDetailsQuoteDetailsId()));
        }
        return Result.success(shippingDetails1);
    }

    @GetMapping
    public Result<List<ShippingDetails>> selectAll(String shippingDetailsShipmentHistoryId){
        List<ShippingDetails> shippingDetails = shippingDetailsService.selectWhere(shippingDetailsShipmentHistoryId);
        return Result.success(shippingDetails);
    }
    @PutMapping
    public Result update(@RequestBody List<ShippingDetails> shippingDetails){
        for(ShippingDetails s : shippingDetails){
            shippingDetailsService.updateById(s);
        }
        return Result.success(shippingDetails);
    }
}
